package first.group.ssh.util;

import java.math.BigInteger;
import java.util.Random;

public class BigIntegerUtil {

    public static BigInteger randomBigInteger(Random random, BigInteger max) {
        var result = new BigInteger(max.bitLength(), random);
        if (result.compareTo(max) >= 0) {
            result = result.mod(max);
        }
        return result;
    }

    public static BigInteger randomBigInteger(Random random, BigInteger min, BigInteger max) {
        var range = max.subtract(min);
        var val = randomBigInteger(random, range);
        return min.add(val);
    }
}
